<template>
  <section class="oa-form__table">
    <h5>{{ approve.name }}</h5>
    <table cellpadding="0" cellspacing="0">
      <tr v-if="$route.query.from != 'new'">
        <td>事务编号</td>
        <td>
          {{ approve.name }}
          <span v-if="approve && approve.code">{{ approve.code }}</span>
        </td>
      </tr>
      <tr>
        <td>流程名称</td>
        <td>
          <span v-if="$route.query.from == 'new'">新建{{ approve.name }}</span>
          <span v-else>
            {{ approve.approve_name }}
          </span>
        </td>
      </tr>
      <tr>
        <td>申请事由</td>
        <td :title="reason"><el-input placeholder="申请事由" type="textarea" v-model="reason" :disabled="$route.query.from != 'new'"/></td>
      </tr>
    </table>
    <h3 class="oa-form__table-title">
      <span v-if="$route.query.from === 'new'">{{ approve.name }}</span>
      <span v-else>
        {{ approve.approve_name }}
      </span>
    </h3>
     <table class="achievement__tab">
      <tr class="border_0">
        <td>考核周期:</td>
        <td>
          <el-date-picker
            value-format="yyyy-MM-dd"
            type="date"
            v-model="applyTime"
            :disabled="$route.query.from !== 'new'"
            placeholder="考核周期">
          </el-date-picker>
        </td>
        <td>部门:</td>
        <td width="400">
          <el-select v-model="department" :disabled="$route.query.from != 'new'" placeholder="请选择">
            <el-option
              v-for="item in departments"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </td>
        <td>姓名:</td>
        <td>
          <el-select v-model="value" style="width:60%" :disabled="$route.query.from != 'new'" placeholder="请选择"  @change="selectStaff($event)">
            <el-option
              v-for="item in staff"
              :key="item.value"
              :label="item.label"
              :value="item">
            </el-option>
          </el-select>
        </td>
        <td>岗位:<span style="display:inline-block;width:100px;padding-left:10px;"><el-input v-model="gangwei" :disabled="$route.query.from !== 'new'" placeholder="岗位"/></span></td>
      </tr>
      <tr>
        <td class="_name">考核指标</td>
        <td class="_name">指标定义</td>
        <td class="_name">权重</td>
        <td class="_name">评分说明</td>
        <td class="_name">数据来源</td>
        <td class="_name">自评</td>
        <td class="_name">评估得分</td>
        <!-- <td class="_name">扣分事项说明</td> -->
      </tr>
      <tr>
         <td rowspan="6">财务</td>
         <td>会计核算</td>
         <td>10%</td>
         <td>及时处理公司销售账务，常规业务发生或单据到达手上不超过24小时处理完毕确保账务完整；保证档案完整（超时1次扣2分 出错1次扣5分）</td>
         <td>直属上级</td>
         <td><el-input v-model="obj.a302" :disabled="$route.query.from !== 'new'" /></td>
         <td><el-input v-model="obj.a314" :disabled="obj.a314Flag" /></td>
      </tr>
      <tr>
         <td>系统流程</td>
         <td>10%</td>
         <td>常规业务发生当天需完成OA事项审核（超时1次扣2分，出错1次扣5分）</td>
         <td>直属上级</td>
         <td><el-input v-model="obj.a303" :disabled="obj.a303Flag" /></td>
         <td><el-input v-model="obj.a315" :disabled="obj.a315Flag" /></td>
      </tr>
      <tr>
         <td>业绩目标达成率</td>
         <td>10%</td>
         <td>业务部累计月业绩目标完成90%以上（80%≤R&lt;90%扣2分，R&lt;80%扣4分，100%≤R&lt;110%加2分，110%≤R&lt;120%加4分，R≥120%加10分）</td>
         <td>直属上级</td>
         <td><el-input v-model="obj.a304" :disabled="obj.a304Flag" /></td>
         <td><el-input v-model="obj.a316" :disabled="obj.a316Flag" /></td>
      </tr>
      <tr>
         <td>应收账款</td>
         <td>10%</td>
         <td>每月应收账款总额控制在550万以内（550&lt;X≤650扣2分，650&lt;X扣4分，500≤X&lt;550加2分，X&lt;500加4分）</td>
         <td>直属上级</td>
         <td><el-input v-model="obj.a305" :disabled="obj.a305Flag" /></td>
         <td><el-input v-model="obj.a317" :disabled="obj.a317Flag" /></td>
      </tr>
      <tr>
         <td>客服配合</td>
         <td>10%</td>
         <td>及时通知客服按应收节点发函；及时跟催客服每周每月应提交的报告；对客服提出的资料需求当天内完成；（超时1次扣2分，出错1次扣5分）</td>
         <td>客服部</td>
         <td><el-input v-model="obj.a306" :disabled="obj.a306Flag" /></td>
         <td><el-input v-model="obj.a318" :disabled="obj.a318Flag" /></td>
      </tr>
      <tr>
         <td>业务核对</td>
         <td>20%</td>
         <td>每月5日提供本月即将到期付款的清单与业务员核对，协助业务员到客户处跟催款项；每月10日前计算业务员提成，并认真与业务员核对，做到及时准确；（超时1次扣2分，出错1次扣5分）</td>
         <td>业务部门</td>
         <td><el-input v-model="obj.a307" :disabled="obj.a307Flag" /></td>
         <td>
           <div>
          业务一部<el-input v-model="obj.a328" :disabled="obj.a328Flag" />
        </div>
        <div>
          业务二部<el-input v-model="obj.a329" :disabled="obj.a329Flag" />
        </div>
        <div>平均得分<el-input v-model="b1" disabled placeholder="平均得分"/></div>
         </td>
      </tr>
       <tr>
         <td></td>
         <td>印章保管</td>
         <td>5%</td>
         <td>保证按公司用印制度执行（出错1次扣5分)</td>
         <td>总经理</td>
         <td><el-input v-model="obj.a308" :disabled="obj.a308Flag" /></td>
         <td><el-input v-model="obj.a320" :disabled="obj.a320Flag" /></td>
      </tr>
       <tr>
         <td rowspan="2">数据整理</td>
         <td rowspan="2">内部数据整理</td>
         <td>5%</td>
         <td>每天下班前与调度核对公司上下画及发布过程中其他特殊状况，整理上刊数据；（超时1次扣2分，出错1次扣5分）</td>
         <td>调度</td>
         <td><el-input v-model="obj.a309" :disabled="obj.a309Flag" /></td>
         <td><el-input v-model="obj.a321" :disabled="obj.a321Flag" /></td>
      </tr>
       <tr>
         <td>10%</td>
         <td>每周五下班前整理客服提供的各项数据报表汇总给财务总监及总经理；每月10日前整理各项数据报表汇总给财务总监及总经理；（超时1次扣2分，出错1次扣5分）</td>
         <td>直属上级</td>
         <td><el-input v-model="obj.a310" :disabled="obj.a310Flag" /></td>
         <td><el-input v-model="obj.a322" :disabled="obj.a322Flag" /></td>
      </tr>
      <tr>
         <td>公司制度执行</td>
         <td>遵守公司制度</td>
         <td>10%</td>
         <td>对公司制度及公司文化的理解和执行（包括根据公司整体规划制定个人业务计划，合理安排个人各项工作时间，遵守公司各项制度等）；协助公司KPI督导</td>
         <td>行政部</td>
         <td><el-input v-model="obj.a311" :disabled="obj.a311Flag" /></td>
         <td><el-input v-model="obj.a323" :disabled="obj.a323Flag" /></td>
      </tr>
      <tr>
        <td rowspan="2">加分项</td>
        <td>增量工作内容</td>
        <td>&nbsp;</td>
        <td>超出岗位职责范围、领导交办较为繁杂的事务、工作表现卓越等</td>
        <td>总经理</td>
        <td><el-input v-model="obj.a312" :disabled="obj.a312Flag" /></td>
        <td><el-input v-model="obj.a324" :disabled="obj.a324Flag" /></td>
      </tr>
      <tr>
        <td>对公司的建议</td>
        <td>&nbsp;</td>
        <td>对市场拓展、业务销售、内部管理等建设性意见</td>
        <td>总经理</td>
        <td><el-input v-model="obj.a313" :disabled="obj.a313Flag" /></td>
        <td><el-input v-model="obj.a325" :disabled="obj.a325Flag" /></td>
      </tr>
      <tr>
        <td colspan="5"></td>
        <td>自评:{{myScore}}</td>
        <td>综合考核率:{{otherScore}}</td>
      </tr>
    </table>
    <history :process="process"></history>
    <files></files>
  </section>
</template>
<script>
import mixin from '@/mixins/index.js'
import history from '../service/components/process'
import files from '../service/components/files'
import { sum } from '@/utils/domUtils.js'
// import { save, info, getAutoKey } from '@/api/oa/index.js'
const obj = {}
for (let i = 301; i <= 325; i++) {
  obj[`a${i}`] = ''
  obj[`a${i}Flag`] = true
}
for (let i = 328; i <= 329; i++) {
  obj[`a${i}`] = ''
  obj[`a${i}Flag`] = true
}
// for (let i = 678; i <= 679; i++) {
//   obj[`a${i}`] = ''
//   obj[`a${i}Flag`] = true
// }
export default {
  mixins: [mixin],
  data () {
    return {
      reason: '',
      truename: '',
      department: '',
      flag: false,
      value: '',
      obj: JSON.parse(JSON.stringify(obj)),
      applyTime: '',
      gangwei: '',
      file_paths: [],
      file_names: [],
      field_ids: [],
      field_vals: [],
      autoField: []
    }
  },
  components: { history, files },
  props: ['curDepartment', 'userInfo', 'approve', 'staff', 'addDofield', 'departments', 'process'],
  computed: {
    uploadArr () {
      return this.$store.state.uploadArr
    },
    b1 () {
      const num = parseFloat((Number(this.obj.a328) + Number(this.obj.a329)) / 2).toFixed(2)
      return num
    },
    myScore () {
      const result = []
      for (let i = 302; i <= 313; i++) {
        if (this.obj[`a${i}`]) {
          result.push(this.obj[`a${i}`])
        }
      }
      return sum(result)
    },
    otherScore () {
      const result = []
      for (let i = 314; i <= 325; i++) {
        if (this.obj[`a${i}`]) {
          result.push(this.obj[`a${i}`])
        }
      }
      result.push(this.b1)
      return sum(result)
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.obj = JSON.parse(JSON.stringify(obj))
      if (this.$route.query.from === 'new') {
        this.disabled = true
      } else {
        this.infoFunc()
        this.addDofieldRender()
      }
    })
  },
  methods: {
  }
}
</script>
